<?php

require_once("Model/ModelsInclude.php");

require_once("Layout/header.php");

/*
 * Istanza generica per accesso ad attributi del model.
 */
$c = Articolo::getInstance();
define("PARENT_PAGE_NAME","Articoli");
define("PAGE_NAME","Modifica Articolo");
define("PAGE_TITLE","Visualizza Dettagli&#47;Modifica Articolo");
global $pagesCtrlerEditLink,$pagesEditLink, $pagesRemoveLink, $pagesCtrlerAddLink;

/*
 * Connessione DB.
 */
$db = new DatabaseManager();
$db->Connect();

/*
 * Stampa dell'header della pagina
 */
printHeader(PAGE_NAME, PAGE_TITLE, $c);

$IDToGet = $_GET["ID"];

$objectToEdit = $c->getFromDB($db, $IDToGet);

if($objectToEdit == NULL)
{
	echo('<p style=\"color:#f00;\"><b>Parametri della richiesta non validi!</b></p>');
	include("Layout/footer.php");
	die();
}

LayoutUtils::printEditPage($db, $objectToEdit, $pagesCtrlerEditLink[PARENT_PAGE_NAME]);

?>
<!-- Tabella associativa della relazione NxN -->

<div class="top-bar">
<h1>Variazioni:</h1>
</div>
<div class="select-bar-void"></div>

<?php

$thisForeignKey = "idArticolo";
$thisForeignValue = $objectToEdit->dataTupla[STD_ID];

$c = VariazioneArticolo::getInstance();
$assocList = $c->getListFromDBByIDArticolo($db,$thisForeignValue);

define("ASSOC_PAGE_NAME","Variazioni Articoli");

LayoutUtils::print_1xN_AssocModelList($db, $thisForeignKey, $thisForeignValue, $c, $assocList,
		$pagesRemoveLink[ASSOC_PAGE_NAME], $pagesEditLink[ASSOC_PAGE_NAME],
		true, $pagesCtrlerAddLink[ASSOC_PAGE_NAME]);

include("Layout/footer.php");

?>
